#include <stdio.h>
#include <malloc.h>
#include <time.h>
#include <assert.h>

#include "menu.h"
#include "event.h"
#include "log2file.h"

// static void Texture_loaging(int x, int y, SDL_Texture *texture, SDL_Renderer *ren)
// {
//     int w, h;
//     SDL_Rect dst_rect;
//     dst_rect.x = x;
//     dst_rect.y = y;
//     SDL_QueryTexture(texture, NULL, NULL, &w, &h);
//     dst_rect.w = w;
//     dst_rect.h = h;
//     SDL_RenderCopy(ren, texture, NULL, &dst_rect);
// }

// static void Text_loading_color(char *text, int x, int y, TTF_Font *tft_font, SDL_Renderer *ren , SDL_Color color )
// {
//     SDL_Surface *surface = TTF_RenderUTF8_Blended(tft_font, text, color);
//     SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surface);
//     SDL_Rect dst_rect;
//     int w, h;
//     dst_rect.x = x;
//     dst_rect.y = y;
//     SDL_QueryTexture(texture, NULL, NULL, &w, &h);
//     dst_rect.w = w;
//     dst_rect.h = h;
//     SDL_RenderCopy(ren, texture, NULL, &dst_rect);

//     SDL_DestroyTexture(texture);
//     SDL_FreeSurface(surface);
// }

static void init_icon_normal(icon_normal_t *p, UICtx_t *pobj)
{
    if (NULL == p->arrows_icon_Texture[0]) {
        char name[64], path[128];
        switch (pobj->devctx.output_res_type.val)
        {
        case OUTPUT_RES_1024X768:
            sprintf(name, "A1-%s-icon-20240428-V1.0", "1024x768");
            break;
        case OUTPUT_RES_1280X720:
            sprintf(name, "A1-%s-icon-20240428-V1.0", "1280x720");
            break;
        case OUTPUT_RES_1280X1024:
            sprintf(name, "A1-%s-icon-20241108-V1.0", "1280x1024");
            break;
        case OUTPUT_RES_1920X1080:
            sprintf(name, "A1-%s-icon-20240428-V1.0", "1920x1080");
            break;
        default:
            sprintf(name, "A1-%s-icon-20240428-V1.0", "720x480");
            break;
        }

        sprintf(path, "./Resources/%s/unselectable-3-arrow-icon.png", name);
        p->arrows_icon_Texture[0] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/3-arrow-icon.png", name);
        p->arrows_icon_Texture[1] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/background_correction.png", name);
        p->background_correction_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/Compass arrow-icon.png", name);
        p->Compass_arrow_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/Compass Calibration-icon.png", name);
        p->Compass_Calibration_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/Compass-icon.png", name);
        p->Compass_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/Image-Brightness-icon.png", name);
        p->image_brightness_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/unselectable-left-arrow-icon.png", name);
        p->left_arrow_icon_Texture[0] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/left-arrow-icon.png", name);
        p->left_arrow_icon_Texture[1] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/unselectable-right-arrow-icon.png", name);
        p->right_arrow_icon_Texture[0] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/right-arrow-icon.png", name);
        p->right_arrow_icon_Texture[1] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/long-focus-icon.png", name);
        p->long_focus_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/unselectable-long-line-icon.png", name);
        p->long_line_icon_Texture[0] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/long-line-icon.png", name);
        p->long_line_icon_Texture[1] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/motion-sensor-left-icon.png", name);
        p->motion_sensor_left_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/motion-sensor-right-icon.png", name);
        p->motion_sensor_right_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/top-menu-line-icon.png", name);
        p->top_menu_line_icon_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/Warning-icon.png", name);
        p->Warning_Texture = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/correction normal.png", name);
        p->cal_status_Texture[0] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/correction ok.png", name);
        p->cal_status_Texture[1] = IMG_LoadTexture(p->renderer, path);
        sprintf(path, "./Resources/%s/correction fail.png", name);
        p->cal_status_Texture[2] = IMG_LoadTexture(p->renderer, path);
        p->tft_font = TTF_OpenFont("./Resources/arial.ttf", 20 * pobj->w_zoom);
    }
}

void update_icon_normal(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int sensor_type = pobj->devctx.sensor_type.val;
    int color_mode = pobj->devctx.color_mode.val;
    int color_mode_tick = pobj->devctx.color_mode_tick.val;
    int zoom = pobj->devctx.zoom.val;
    int compass = pobj->devctx.compass.val;
    int compass_angle = pobj->devctx.compass_angle.val;
    int motion = pobj->devctx.motion.val;
    int hori_angle = pobj->devctx.hori_angle.val;
    int vert_angle = pobj->devctx.vert_angle.val;
    int bg_cal_tick = pobj->devctx.bg_cal_tick.val;
    int img_brightness = pobj->devctx.img_brightness.val;
    int img_brightness_tick = pobj->devctx.img_brightness_tick.val;

    init_icon_normal(menu, pobj);

    int icon_w, icon_h;

    if (img_brightness_tick) {
        for (int i = 0; i < img_brightness + 1; i ++) {
            SDL_QueryTexture(menu->image_brightness_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h); 
            dst_rect.x = osd_width - 26 * w_zoom - dst_rect.w * (11 - i) - 3 * w_zoom * (10 - i);
            dst_rect.y = 21 * h_zoom;
            SDL_RenderCopy(menu->renderer, menu->image_brightness_icon_Texture, NULL, &dst_rect);
        }
    }

    if (TYPE_VIS_1920X1080 != sensor_type && color_mode_tick) {
        char text_color_mode[][2][6][64] = {
            {
                {"Black Hot", "White Hot", "Red Hot", "Blue-green Flames", "Iron Rainbow", "Spectrum"}, 
                {"黑热", "白热", "红热", "蓝绿火焰", "铁红", "频谱"},
            },
            {
                {"Black hot", "White hot", "Red hot", "Rainbow", "Ironbow", "Night"}, 
                {"黑热", "白热", "红热", "彩虹", "铁红", "微光"},
            }
        };
        int sel;
        switch (sensor_type)
        {
        case TYPE_FPGA_256X192:
        case TYPE_FPGA_384X288:
        case TYPE_FPGA_640X512:
            sel = 1;
            break;
        
        default:
            sel = 0;
            break;
        }
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_color_mode[sel][language][color_mode], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = 21 * h_zoom;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }

    if (zoom) {
        sprintf(text, "%dX", zoom + 1);
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = 26 * w_zoom;
        dst_rect.y = 20 * h_zoom;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }

    if (compass) {
        SDL_QueryTexture(menu->Compass_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        icon_w = dst_rect.w, icon_h = dst_rect.h;
        dst_rect.w = icon_w * 90 / 450;
        dst_rect.h = icon_h;
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = osd_height - dst_rect.h;

        SDL_Rect src_rect;
        src_rect.x = (int)(compass_angle * (icon_w * 360 / 450) / 360);
        src_rect.y = 0;
        src_rect.w = dst_rect.w;
        src_rect.h = dst_rect.h;
        SDL_RenderCopy(menu->renderer, menu->Compass_icon_Texture, &src_rect, &dst_rect);

        SDL_QueryTexture(menu->Compass_arrow_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h); 
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = osd_height - icon_h - dst_rect.h - 5 * h_zoom;
        SDL_RenderCopy(menu->renderer, menu->Compass_arrow_icon_Texture, NULL, &dst_rect);
    
        sprintf(text, "%d°", compass_angle);
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = dst_rect.y - dst_rect.h - 5 * h_zoom;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }

    if (motion) {
        SDL_QueryTexture(menu->motion_sensor_left_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h); 
        dst_rect.x = 0;
        dst_rect.y = (osd_height - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, menu->motion_sensor_left_icon_Texture, NULL, &dst_rect);

        sprintf(text, "%d°", hori_angle);
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = 10 * w_zoom;
        dst_rect.y = 320 * h_zoom;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        SDL_QueryTexture(menu->motion_sensor_right_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h); 
        dst_rect.x = osd_width - dst_rect.w;
        dst_rect.y = (osd_height - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, menu->motion_sensor_right_icon_Texture, NULL, &dst_rect);

        sprintf(text, "%d°", vert_angle);
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = osd_width - dst_rect.w - 10 * w_zoom;
        dst_rect.y = 318 * h_zoom;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }

    if (bg_cal_tick) {
        SDL_QueryTexture(menu->background_correction_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = (osd_height - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, menu->background_correction_Texture, NULL, &dst_rect);
    }
}

void update_icon_mainmenu1(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int menu_sel = pobj->devctx.mainmenu1.curnode.val;
    int menu_max = pobj->devctx.mainmenu1.curnode.max;
    int sensor_type = pobj->devctx.sensor_type.val;

    init_icon_normal(menu, pobj);

    /* menu */
    if (TYPE_VIS_1920X1080 == sensor_type) {
        pos_y = 75 * h_zoom;
    } else {
        pos_y = 99 * h_zoom;
    }
    char text_tittle[2][64] = {"Menu", "菜单"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;    /* long_focus_icon_Texture 的起始位置 y 坐标 */
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * menu_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x; /* long_focus_icon_Texture 的起始位置 x 坐标 */
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][nid_menu_end][2][64] = { 
        {
            {"Image", "图像界面"},
            {"Reticle", "十字分划"},
            {"IMU", "运动姿态"},
            {"System", "系统设置"},
            {"Exit", "退出"},
        },
        {
            {"Image", "图像界面"},
            {"Camera setting", "微光镜头设置"},
            {"Reticle", "十字分划"},
            {"IMU", "运动姿态"},
            {"System", "系统设置"},
            {"Exit", "退出"},
        }
    };
    for (int i = 0; i < menu_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = (pos_y + long_focus_icon_h) + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[TYPE_VIS_1920X1080 == sensor_type][i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (i != menu_max) {
            SDL_QueryTexture(menu->arrows_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = (pos_x + long_focus_icon_w) - dst_rect.w - 20 * w_zoom;
            dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[1], NULL, &dst_rect);
        }
    }
}

void update_icon_image(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 148 * h_zoom;
    char text_tittle[2][64] = {"Image", "图像界面"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Image Adjust", "图像调整"},
        {"Image Setting", "图像设置"},
        {"Return", "返回"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (status_sel_max != i) {
            SDL_QueryTexture(menu->arrows_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[1], NULL, &dst_rect);
        }
    }
}

void update_icon_image_adjust(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int menu_sel = pobj->devctx.image_adjust.curnode.val;
    int menu_max = pobj->devctx.image_adjust.curnode.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 75 * h_zoom;
    char text_tittle[2][64] = {"Image Adjust", "图像调整"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * menu_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Brightness", "亮度"},
        {"Contrast", "对比度"},
        // {"Detail Enhance", "细节增强"},
        {"Sharpness", "锐度"},
        // {"Gamma", "伽马值"},
        {"DDE", "细节增强"},
        {"Denoise", "降噪"},
        {"Return", "返回"},
    };
    for (int i = 0; i < menu_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (menu_max != i) {
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 70 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);

            sprintf(text, "%d", pobj->devctx.image_adjust.node[i]->val);
            surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 70 * w_zoom + (70 * w_zoom - 20 * w_zoom - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        }
    }
}

void update_icon_image_setting(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int menu_sel = pobj->devctx.image_setting.curnode.val;
    int menu_max = pobj->devctx.image_setting.curnode.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 124 * h_zoom;
    char text_tittle[2][64] = {"Image Setting", "图像设置"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * menu_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Mirror", "镜像"},
        {"Flip", "翻转"},
        {"EIS", "电子防抖"},
        {"Return", "返回"},
    };
    char text_onoff[][2][64] = {
        {"OFF", "关"},
        {"ON", "开"},
    };
    for (int i = 0; i < menu_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (menu_max != i) {
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 80 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);

            /* onoff */
            surface = TTF_RenderUTF8_Blended(menu->tft_font, text_onoff[pobj->devctx.image_setting.node[i]->val][language], color);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 80 * w_zoom + (80 * w_zoom - 20 * w_zoom - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        }
    }
}

void update_icon_camera_setting(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;
    int VIS_mode = pobj->devctx.VIS_mode.val;
    int EC = pobj->devctx.EC.val;
    int WDR = pobj->devctx.WDR.val;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 99 * h_zoom;
    char text_tittle[2][64] = {"Camera setting", "微光镜头设置"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;

    /* focus */
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Day&Night", "日夜模式"},
        {"Exposure compensation", "曝光补偿"},
        {"WDR", "宽动态"},
        {"WB setting", "白平衡设置"},
        {"Return", "返回"},
    };
    char text_VIS_mode[][2][64] = {
            {"Day", "白天"},
            {"Night", "夜晚"},
            {"Dusk", "傍晚"},
    };
    char text_EC[][64] = {"-2.0", "-1.7", "-1.3", "-1.0", "-0.7", "-0.3", "0", "+0.3", "+0.7", "+1.0", "+1.3", "+1.7", "+2.0"};
    char text_WDR[][2][64] = {
            {"Low", "低"},
            {"Middle", "中"},
            {"High", "高"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (nid_camera_setting_WB != i && nid_camera_setting_return != i) {
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 85 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);
            switch (i)
            {
            case nid_camera_setting_VIS_mode:
                surface = TTF_RenderUTF8_Blended(menu->tft_font, text_VIS_mode[VIS_mode][language], color);
                break;
            case nid_camera_setting_EC:
                surface = TTF_RenderUTF8_Blended(menu->tft_font, text_EC[EC], color);
                break;
            case nid_camera_setting_WDR:
                surface = TTF_RenderUTF8_Blended(menu->tft_font, text_WDR[WDR][language], color);
                break;
            }
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 85 * w_zoom + (85 * w_zoom - 20 * w_zoom - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        }

        /* WB seting */
        if (nid_camera_setting_WB == i) {
            SDL_QueryTexture(menu->arrows_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[1], NULL, &dst_rect);
        }
    }
}

void update_icon_WB_setting(icon_normal_t *menu, void *pso)
{
    SDL_Color color[] = {{128, 128, 128, 255}, {255, 255, 255, 255}};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;
    int WB_mode = pobj->devctx.WB_mode.val;
    int color_temp = pobj->devctx.color_temp.val;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 124 * h_zoom;
    char text_tittle[2][64] = {"WB setting", "白平衡设置"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color[1]);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"White Balance", "白平衡"},
        {"Color Temperature", "色温"},
        {"Return", "返回"},
    };
    char text_WB_mode[][2][64] = {
        {"Auto", "自动"},
        {"Manual", "手动"},
    };
    char text_color_temp[][64] = {"3000K", "5000K", "8000K"};
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color[(0 == WB_mode && 1 == i) ? 0 : 1]);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (status_sel_max != i) {
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 85 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[(0 == WB_mode && 1 == i) ? 0 : 1], NULL, &dst_rect);

            switch (i)
            {
            case 0: // WB_mode
                surface = TTF_RenderUTF8_Blended(menu->tft_font, text_WB_mode[WB_mode][language], color[1]);
                break;
            case 1: // color_temp
                surface = TTF_RenderUTF8_Blended(menu->tft_font, text_color_temp[color_temp], color[(0 == WB_mode && 1 == i) ? 0 : 1]);
                break;
            }
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 85 * w_zoom + (85 * w_zoom - 20 * w_zoom - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        }
    }
}

void update_icon_reticle(icon_normal_t *menu, void *pso)
{
    SDL_Color color[] = {{128, 128, 128, 255}, {255, 255, 255, 255}};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;
    // int menu_entry = pobj->devctx.menu_entry.val;
    int reticle = pobj->devctx.reticle.val;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 124 * h_zoom;
    char text_tittle[2][64] = {"Reticle", "十字分划"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color[1]);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Reticle Enable", "十字分划开关"},
        {"Reticle Color", "十字分划颜色"},
        {"Reticle Coordinate", "十字分划设置"},
        {"Return", "返回"},
    };
    char text_onoff[][2][64] = {
        {"OFF", "关"},
        {"ON", "开"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[(!reticle && (1 == i || 2 == i)) ? 0 : 1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[(!reticle && (1 == i || 2 == i)) ? 0 : 1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color[(!reticle && (1 == i || 2 == i)) ? 0 : 1]);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        switch (i)
        {
        case 0:
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 80 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);

            surface = TTF_RenderUTF8_Blended(menu->tft_font, text_onoff[reticle][language], color[1]);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 80 * w_zoom + (80 * w_zoom - 20 - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
            break;
        case 1:
        case 2:
            SDL_QueryTexture(menu->arrows_icon_Texture[(!reticle && (1 == i || 2 == i)) ? 0 : 1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[(!reticle && (1 == i || 2 == i)) ? 0 : 1], NULL, &dst_rect);
            break;
        }
    }
}

void update_icon_cross_color_setting(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    // float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 99 * h_zoom;
    char text_tittle[2][64] = {"Reticle Color", "十字分划颜色"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;

    /* focus */
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    // int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"White", "白色"},
        {"Black", "黑色"},
        {"Red", "红色"},
        {"Green", "绿色"},
        {"Return", "返回"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }
}

void update_icon_gun_cal(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    int cross_pos_x = pobj->devctx.cross_pos.center_x.val;
    int cross_pos_y = pobj->devctx.cross_pos.center_y.val;

    init_icon_normal(menu, pobj);

    int text_w, text_h;
    TTF_SizeUTF8(menu->tft_font, "X=000pixel", &text_w, &text_h);
    sprintf(text, "X=%dpixel", cross_pos_x);
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - text_w * 2 - 40 * w_zoom) / 2;
    dst_rect.y = 443 * h_zoom;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    sprintf(text, "Y=%dpixel", -cross_pos_y);
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = dst_rect.x + text_w + 40 * w_zoom;
    dst_rect.y = 443 * h_zoom;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);
}

void update_icon_nine_axis_setting(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;
    int motion = pobj->devctx.motion.val;
    int compass = pobj->devctx.compass.val;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 124 * h_zoom;
    char text_tittle[2][64] = {"IMU", "运动姿态"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Gyroscope", "陀螺仪"},
        {"Compass", "电子罗盘"},
        {"Compass Calibration", "电子罗盘校准"},
        {"Return", "返回"},
    };
    char text_onoff[][2][64] = {
        {"OFF", "关"},
        {"ON", "开"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (0 == i || 1 == i) {
            /* left arrow */
            SDL_QueryTexture(menu->left_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 80 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->left_arrow_icon_Texture[1], NULL, &dst_rect);

            int left_arrow_icon_w = dst_rect.w;
            /* right arrow */
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);

            /* onoff */
            switch (i)
            {
            case 0:
                sprintf(text, "%s", text_onoff[motion][language]);
                break;
            case 1:
                sprintf(text, "%s", text_onoff[compass][language]);
                break;
            }
            surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - 80 * w_zoom + (80 * w_zoom - 20 * w_zoom - left_arrow_icon_w - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        } else if (2 == i) {
            SDL_QueryTexture(menu->arrows_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[1], NULL, &dst_rect);
        }
    }
}

void update_icon_system(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 99 * h_zoom;
    char text_tittle[2][64] = {"System", "系统设置"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;

    /* focus */
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_w = dst_rect.w;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"Language", "语言设置"},
        {"Factory Reset", "恢复出厂设置"},
        {"Information", "设备信息"},
        {"Return", "返回"},
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x + 20 * w_zoom;
        dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        if (nid_system_langua == i) {
            SDL_QueryTexture(menu->right_arrow_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->right_arrow_icon_Texture[1], NULL, &dst_rect);

            char text_language[][64] = {"English", "简体中文"};
            surface = TTF_RenderUTF8_Blended(menu->tft_font, text_language[language], color);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = dst_rect.x - 5 * w_zoom - dst_rect.w;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        } else if (nid_system_return != i) {
            SDL_QueryTexture(menu->arrows_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x + long_focus_icon_w - dst_rect.w - 20 * w_zoom;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->arrows_icon_Texture[1], NULL, &dst_rect);
        }
    }
}

void update_icon_language(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    // float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int status_sel_max = pobj->devctx.status_sel.max;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 148 * h_zoom;
    char text_tittle[2][64] = {"Language", "语言设置"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    int long_focus_icon_h = dst_rect.h;
    char text_menu[][2][64] = {
        {"English", "English"},
        {"简体中文", "简体中文"},
        {"Return", "返回"}
    };
    for (int i = 0; i < status_sel_max + 1; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        /* menu text */
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_menu[i][language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }
}

void update_icon_compass_cal(icon_normal_t *menu, void *pso)
{
    SDL_Rect dst_rect;

    UICtx_t *pobj = (UICtx_t*)pso;
    int osd_width = pobj->res_info.osd_width;
    int osd_height = pobj->res_info.osd_height;

    init_icon_normal(menu, pobj);

    SDL_QueryTexture(menu->Compass_Calibration_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = (osd_height - dst_rect.h) / 2;
    SDL_RenderCopy(menu->renderer, menu->Compass_Calibration_icon_Texture, NULL, &dst_rect);
}

void update_icon_factory_reset(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    // char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    // float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;
    int status_sel = pobj->devctx.status_sel.val;
    int menu_entry = pobj->devctx.menu_entry.val;
    int factory_reset = pobj->devctx.factory_reset.val;

    init_icon_normal(menu, pobj);

    if (factory_reset) {
        char text_loading[][64] = {"Loading", "等待中"};
        TTF_SetFontStyle(menu->tft_font, TTF_STYLE_BOLD);	// 设置粗体
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_loading[language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        int text_loading_w = dst_rect.w, text_loading_h = dst_rect.h;

        SDL_QueryTexture(menu->Warning_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = (osd_height - dst_rect.h - 12 * h_zoom - text_loading_h) / 2;
        SDL_RenderCopy(menu->renderer, menu->Warning_Texture, NULL, &dst_rect);

        dst_rect.x = (osd_width - text_loading_w) / 2;
        dst_rect.y = dst_rect.y + dst_rect.h + 12 * h_zoom;
        dst_rect.w = text_loading_w;
        dst_rect.h = text_loading_h;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
        TTF_SetFontStyle(menu->tft_font, TTF_STYLE_NORMAL);
    } else {
        /* menu */
        if (0 == menu_entry) {
            pos_y = 172 * h_zoom;
        } else {
            pos_y = 148 * h_zoom;
        }
        char text_tittle[2][64] = {"Factory Reset", "恢复出厂设置"};
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);

        /* short line */
        pos_y += dst_rect.h + 13 * h_zoom;
        SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y;
        SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

        pos_y += 20 * h_zoom;
        stride_h = 50 * h_zoom;
        SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y + stride_h * (menu_entry ? (status_sel + 1) : status_sel);
        SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

        int long_focus_icon_h = dst_rect.h;
        char text_yesno[][2][64] = {
            {"Are you sure to reset settings?", "确定要恢复出厂设置?"},
            {"No", "否"},
            {"Yes", "是"},
        };
        for (int i = 0; i < (menu_entry ? 3 : 2); i++) {
            /* long line */
            SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = (osd_width - dst_rect.w) / 2;
            dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
            SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

            /* menu text */
            surface = TTF_RenderUTF8_Blended(menu->tft_font, text_yesno[menu_entry ? i : (i + 1)][language], color);
            texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
            SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = (osd_width - dst_rect.w) / 2;
            dst_rect.y = pos_y + stride_h * i + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(surface);
        }
    }
}

void update_icon_ver_info(icon_normal_t *menu, void *pso)
{
    SDL_Color color = {255, 255, 255, 255};
    char text[256] = {0};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    // float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    // int osd_height = pobj->res_info.osd_height;
    int language = pobj->devctx.language.val;

    init_icon_normal(menu, pobj);

    /* menu */
    pos_y = 100 * h_zoom;
    char text_tittle[2][64] = {"Information", "设备信息"};
    surface = TTF_RenderUTF8_Blended(menu->tft_font, text_tittle[language], color);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    int long_focus_icon_h = dst_rect.h;

    char ver_info_txt[][2][64] = {
        {"Product Model", "产品型号"},
        {"HW Version", "硬件版本"},
        {"GUI Version", "GUI版本"},
        {"SW Version", "软件版本"},
        {"SN", "SN"},
    };
    for (int i = 0; i < 5; i++) {
        /* long line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        switch (i)
        {
        case 0:
            sprintf(text, "%s: %s", ver_info_txt[i][language], pobj->sys_info.model_name);
            break;
        case 1:
            sprintf(text, "%s: %s", ver_info_txt[i][language], pobj->sys_info.hw_ver);
            break;
        case 2:
            sprintf(text, "%s: %s", ver_info_txt[i][language], pobj->sys_info.gui_ver);
            break;
        case 3:
            sprintf(text, "%s: %s", ver_info_txt[i][language], pobj->sys_info.sys_ver);
            break;
        case 4:
            sprintf(text, "%s: %s", ver_info_txt[i][language], pobj->sys_info.sn);
            break;
        }
        surface = TTF_RenderUTF8_Blended(menu->tft_font, text, color);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = (osd_width - dst_rect.w) / 2;
        dst_rect.y = (pos_y + stride_h * i) + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }
}

void update_icon_engineering_update(icon_normal_t *menu, void *pso)
{
    SDL_Color color[] = {{255, 255, 255, 255}, {0, 255, 0, 255}, {255, 0, 0, 255}};
    SDL_Surface *surface;
    SDL_Texture *texture;
    SDL_Rect dst_rect;
    int pos_x, pos_y, stride_h;

    UICtx_t *pobj = (UICtx_t*)pso;
    float w_zoom = pobj->w_zoom;
    float h_zoom = pobj->h_zoom;
    int osd_width = pobj->res_info.osd_width;
    int status_sel = pobj->devctx.status_sel.val;

    init_icon_normal(menu, pobj);
    TTF_Font *tft_font = TTF_OpenFont("./Resources/arial.ttf", 16 * pobj->w_zoom);

    pos_y = 50 * h_zoom;

    /* text tittle */
    char text_tittle[64] = {"工程模式"};
    surface = TTF_RenderUTF8_Blended(tft_font, text_tittle, color[0]);
    texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
    SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);

    /* short line */
    pos_y += dst_rect.h + 13 * h_zoom;
    SDL_QueryTexture(menu->top_menu_line_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y;
    SDL_RenderCopy(menu->renderer, menu->top_menu_line_icon_Texture, NULL, &dst_rect);

    pos_y += 20 * h_zoom;
    stride_h = 50 * h_zoom;
    /* focus */
    SDL_QueryTexture(menu->long_focus_icon_Texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
    dst_rect.x = (osd_width - dst_rect.w) / 2;
    dst_rect.y = pos_y + stride_h * 3 * status_sel;
    SDL_RenderCopy(menu->renderer, menu->long_focus_icon_Texture, NULL, &dst_rect);

    pos_x = dst_rect.x;
    int long_focus_icon_h = dst_rect.h;
    char text_menu[][128] = {
        {"1.NUC矫正，请按下面步骤操作："},
        {"1)在常温下对准25度均匀面，保持设备稳定，同时长按左右键，采集图像"},
        {"2)同时长按上下键3秒，进行矫正运算，保存参数"},
        {"2.两点矫正，请按下面步骤依次操作："},
        {"1)对准10度黑体，同时长按左右键3秒，采集低温图像"},
        {"2)对准50度黑体，同时长按左右键3秒，采集高温图像"},
        {"3)同时长按上下键3秒，进行矫正运算，等待15秒保存参数"}
    };

    int icon_cal_status = 0;
    for (int i = 0; i < 7; i++) {
        /* line */
        SDL_QueryTexture(menu->long_line_icon_Texture[1], NULL, NULL, &dst_rect.w, &dst_rect.h);
        dst_rect.x = pos_x;
        dst_rect.y = pos_y + long_focus_icon_h + stride_h * i;
        SDL_RenderCopy(menu->renderer, menu->long_line_icon_Texture[1], NULL, &dst_rect);

        if (0 != i && 3 != i) {
            SDL_QueryTexture(menu->cal_status_Texture[pobj->devctx.cal_status[i].val], NULL, NULL, &dst_rect.w, &dst_rect.h);
            dst_rect.x = pos_x;
            dst_rect.y = pos_y + i * stride_h + (long_focus_icon_h - dst_rect.h) / 2;
            SDL_RenderCopy(menu->renderer, menu->cal_status_Texture[pobj->devctx.cal_status[i].val], NULL, &dst_rect);
            icon_cal_status = dst_rect.w;
        }

        /* text menu */
        surface = TTF_RenderUTF8_Blended(tft_font, text_menu[i], color[pobj->devctx.cal_status[i].val]);
        texture = SDL_CreateTextureFromSurface(menu->renderer, surface);
        SDL_QueryTexture(texture, NULL, NULL, &dst_rect.w, &dst_rect.h);
        if (0 == i || 3 == i) {
            dst_rect.x = pos_x + 13 * w_zoom;
        } else {
            dst_rect.x = pos_x + 13 * w_zoom + icon_cal_status;
        }
        dst_rect.y = pos_y + i * stride_h + (long_focus_icon_h - dst_rect.h) / 2;
        SDL_RenderCopy(menu->renderer, texture, NULL, &dst_rect);
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
    }
    TTF_CloseFont(tft_font);
}